import { ipcMain } from "electron";
import { FxProtocolHandler } from "../lib/FxProtocolHandler";
//import { ISignaLightConfig } from "../../renderer/src/interface";


export default function initApi(mainWindow) {
  const serial = new FxProtocolHandler("com5");
    
  serial.open().then( () => {
      mainWindow.webContents.send("pub-serial-status", {code:200}); //串口打开成功
  }).catch((err)=>{
      mainWindow.webContents.send("pub-serial-status", {code:-1,err}) //串口打开失败
  });
    

  ipcMain.handle("getRealTimeStatus", async () => await serial.getRealTimeStatus()); //查询实时状态

  ipcMain.handle("getSchemeList",async(_,index:number)=> await serial.getSchemeList(index)) //获取方案

  ipcMain.on("enq",()=> serial.send(Buffer.from([0x05])))

  ipcMain.handle("downloadScheme",async (_,list:string,schemeNum:number)=> await serial.downloadSchemeList(list,schemeNum))

  ipcMain.handle("applyScheme",async ()=> await serial.applyScheme() )

}
